home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 4: GNU Archives / Linux Cubed Series 4 - GNU Archives.iso / gnu / binutils.7 / binutils / binutils-2.7 / ld / testsuite / ld-shared / shared.exp < prev    next >
Encoding:
Text File  |  1996-07-04  |  8.6 KB  |  249 lines

  1. # Expect script for ld-shared tests
  2. #   Copyright (C) 1994, 1995, 1996 Free Software Foundation
  3. #
  4. # This file is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. #
  16. # Written by Ian Lance Taylor (ian@cygnus.com)
  17. #
  18.  
  19. # Make sure that ld can generate ELF shared libraries.
  20. # Note that linking against ELF shared libraries is tested by the
  21. # bootstrap test.
  22.  
  23. # This test can only be run if ld generates native executables.
  24. if ![isnative] then {return}
  25.  
  26. # This test can only be run on a couple of ELF platforms.
  27. # Square bracket expressions seem to confuse istarget.
  28. if { ![istarget i386-*-sysv4*] \
  29.      && ![istarget i486-*-sysv4*] \
  30.      && ![istarget i586-*-sysv4*] \
  31.      && ![istarget i386-*-unixware] \
  32.      && ![istarget i486-*-unixware] \
  33.      && ![istarget i586-*-unixware] \
  34.      && ![istarget i386-*-elf*] \
  35.      && ![istarget i486-*-elf*] \
  36.      && ![istarget i586-*-elf*] \
  37.      && ![istarget i386-*-linux*] \
  38.      && ![istarget i486-*-linux*] \
  39.      && ![istarget i586-*-linux*] \
  40.      && ![istarget m68k-*-linux*] \
  41.      && ![istarget mips*-*-irix5*] \
  42.      && ![istarget sparc*-*-elf] \
  43.      && ![istarget sparc*-*-solaris2*] \
  44.      && ![istarget sparc*-*-sunos4*] \
  45.      && ![istarget rs6000*-*-aix*] \
  46.      && ![istarget powerpc*-*-aix*] } {
  47.     return
  48. }
  49.  
  50. if { [istarget i386-*-linuxaout*] \
  51.      || [istarget i486-*-linuxaout*] \
  52.      || [istarget i586-*-linuxaout*] \
  53.      || [istarget i386-*-linuxoldld*] \
  54.      || [istarget i486-*-linuxoldld*] \
  55.      || [istarget i586-*-linuxoldld*] \
  56.      || [istarget m68k-*-linuxaout*] } {
  57.     return
  58. }
  59.  
  60. set tmpdir tmpdir
  61. set SHCFLAG ""
  62.  
  63. if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  64.  
  65.     # AIX shared libraries do not seem to support useful features,
  66.     # like overriding the shared library function or letting the
  67.     # shared library refer to objects defined in the main program.  We
  68.     # avoid testing those features.
  69.     set SHCFLAG "-DXCOFF_TEST"
  70.  
  71.     # The AIX 3.2.5 loader appears to randomly fail when loading
  72.     # shared libraries from NSF mounted partitions, so we avoid any
  73.     # potential problems by using a local directory.
  74.     catch {exec /bin/sh -c "echo $$"} pid
  75.     set tmpdir /usr/tmp/ld.$pid
  76.     catch "exec mkdir $tmpdir" exec_status
  77.  
  78.     # On AIX, we need to explicitly export the symbols the shared
  79.     # library is going to provide, and need.
  80.     set file [open $tmpdir/xcoff.exp w]
  81.     puts $file shlibvar1
  82.     puts $file shlibvar2
  83.     puts $file shlib_shlibvar1
  84.     puts $file shlib_shlibvar2
  85.     puts $file shlib_shlibcall
  86.     puts $file shlib_shlibcalled
  87.     puts $file shlib_checkfunptr1
  88.     puts $file shlib_getfunptr1
  89.     puts $file shlib_check
  90.     close $file
  91. }
  92.  
  93. # The test procedure.
  94. proc shared_test { progname testname main sh1 sh2 dat } {
  95.     global ld
  96.     global srcdir
  97.     global subdir
  98.     global exec_output
  99.     global host_triplet
  100.     global tmpdir
  101.  
  102.     # Build the shared library.
  103.     # On AIX, we need to use an export file.
  104.     set shared -shared
  105.     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  106.     set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
  107.     }
  108.     if {![ld_simple_link $ld $tmpdir/$progname.so "$shared $tmpdir/$sh1 $tmpdir/$sh2"]} {
  109.         fail "$testname"
  110.         return
  111.     }
  112.  
  113.     # Link against the shared library.  Use -rpath so that the
  114.     # dynamic linker can locate the shared library at runtime.
  115.     # On AIX, we must include /lib in -rpath, as otherwise the loader
  116.     # can not find -lc.
  117.     set rpath $tmpdir
  118.     if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  119.     set rpath /lib:$tmpdir
  120.     }
  121.     if ![ld_link $ld $tmpdir/$progname "-rpath $rpath $tmpdir/$main $tmpdir/$progname.so"] {
  122.         fail "$testname"
  123.         return
  124.     }
  125.  
  126.     # Run the resulting program
  127.     send_log "$tmpdir/$progname >$tmpdir/$progname.out\n"
  128.     verbose "$tmpdir/$progname >$tmpdir/$progname.out"
  129.     catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
  130.     if ![string match "" $exec_output] then {
  131.     send_log "$exec_output\n"
  132.     verbose "$exec_output"
  133.     fail "$testname"
  134.         return
  135.     }
  136.  
  137.     send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
  138.     verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
  139.     catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
  140.     set exec_output [prune_system_crud $host_triplet $exec_output]
  141.  
  142.     if {![string match "" $exec_output]} then {
  143.     send_log "$exec_output\n"
  144.     verbose "$exec_output"
  145.     fail "$testname"
  146.         return
  147.     }
  148.  
  149.     pass "$testname"
  150. }
  151.  
  152. if [istarget mips*-*-*] {
  153.     set picflag ""
  154. } else {
  155.     # Unfortunately, the gcc argument is -fpic and the cc argument is
  156.     # -KPIC.  We have to try both.
  157.     set picflag "-fpic"
  158.     send_log "$CC $picflag\n"
  159.     verbose "$CC $picflag"
  160.     catch "exec $CC $picflag" exec_output
  161.     send_log "$exec_output\n"
  162.     verbose "--" "$exec_output"
  163.     if { [string match "*illegal option*" $exec_output] \
  164.      || [string match "*option ignored*" $exec_output] \
  165.      || [string match "*unrecognized option*" $exec_output] \
  166.      || [string match "*passed to ld*" $exec_output] } {
  167.     if [istarget *-*-sunos4*] {
  168.         set picflag "-pic"
  169.     } else {
  170.         set picflag "-KPIC"
  171.     }
  172.     }
  173. }
  174. verbose "Using $picflag to compile PIC code"
  175.  
  176. # Compile the main program.
  177. if ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
  178.     unresolved "shared (non PIC)"
  179.     unresolved "shared"
  180. } else {
  181.     # The shared library is composed of two files.  First compile them
  182.     # without using -fpic.  That should work on an ELF system,
  183.     # although it will be less efficient because the dynamic linker
  184.     # will need to do more relocation work.  However, note that not
  185.     # using -fpic will cause some of the tests to return different
  186.     # results.
  187.     if { ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
  188.      || ![ld_compile "$CC $CFLAGS $SHCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
  189.     unresolved "shared (non PIC)"
  190.     } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  191.     shared_test shnp "shared (nonPIC)" mainnp.o sh1np.o sh2np.o xcoff
  192.     } else {
  193.     # SunOS can not handle non PIC code in a shared library
  194.     setup_xfail "*-*-sunos4*"
  195.     shared_test shnp "shared (non PIC)" mainnp.o sh1np.o sh2np.o shared
  196.     } }
  197.  
  198.     # Now compile the code using -fpic.
  199.  
  200.     if { ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o] 
  201.      || ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
  202.     unresolved "shared"
  203.     } else {
  204.     # SunOS can not compare function pointers correctly
  205.     if [istarget "*-*-sunos4*"] {
  206.         shared_test shp "shared" mainnp.o sh1p.o sh2p.o sun4
  207.     } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  208.         shared_test shp "shared" mainnp.o sh1p.o sh2p.o xcoff
  209.     } else {
  210.         shared_test shp "shared" mainnp.o sh1p.o sh2p.o shared
  211.     } }
  212.     }
  213. }
  214.  
  215. # Now do the same tests again, but this time compile main.c PIC.
  216. if ![ld_compile "$CC $CFLAGS $SHCFLAG $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
  217.     unresolved "shared (PIC main, non PIC so)"
  218.     unresolved "shared (PIC main)"
  219. } else {
  220.     if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
  221.         if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  222.         shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
  223.     } else {
  224.         # SunOS can not handle non PIC code in a shared library
  225.         setup_xfail "*-*-sunos4*"
  226.         shared_test shmpnp "shared (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o shared
  227.     }
  228.     } else {
  229.     unresolved "shared (PIC main, non PIC so)"
  230.     }
  231.  
  232.     if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
  233.         if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  234.         shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o xcoff
  235.     } else {
  236.         shared_test shmpp "shared (PIC main)" mainp.o sh1p.o sh2p.o shared
  237.     }
  238.     } else {
  239.     unresolved "shared (PIC main)"
  240.     }
  241. }
  242.  
  243. if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
  244.     # Remove the temporary directory.
  245.     catch "exec rm -rf $tmpdir" exec_status
  246. }
  247.